package com.erp.gather.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.gather.domain.bo.ErpSellerCollectProductSkuBo;
import com.erp.gather.domain.vo.ErpSellerCollectProductSkuVo;
import com.erp.gather.service.IErpSellerCollectProductSkuService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 个人采集商品SKU
 *
 * @author erp
 * @date 2023-06-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerCollectProductSku")
public class ErpSellerCollectProductSkuController extends BaseController {

    private final IErpSellerCollectProductSkuService iErpSellerCollectProductSkuService;

    /**
     * 查询个人采集商品SKU列表
     */
    @SaCheckPermission("seller:sellerCollectProductSku:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSellerCollectProductSkuVo> list(ErpSellerCollectProductSkuBo bo, PageQuery pageQuery) {
        return iErpSellerCollectProductSkuService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取个人采集商品SKU详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("seller:sellerCollectProductSku:query")
    @GetMapping("/{id}")
    public R<ErpSellerCollectProductSkuVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSellerCollectProductSkuService.queryById(id));
    }

    /**
     * 新增个人采集商品SKU
     */
    @SaCheckPermission("seller:sellerCollectProductSku:add")
    @Log(title = "个人采集商品SKU", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerCollectProductSkuBo bo) {
        return toAjax(iErpSellerCollectProductSkuService.insertByBo(bo));
    }

    /**
     * 修改个人采集商品SKU
     */
    @SaCheckPermission("seller:sellerCollectProductSku:edit")
    @Log(title = "个人采集商品SKU", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerCollectProductSkuBo bo) {
        return toAjax(iErpSellerCollectProductSkuService.updateByBo(bo));
    }

    /**
     * 删除个人采集商品SKU
     *
     * @param ids 主键串
     */
    @SaCheckPermission("seller:sellerCollectProductSku:remove")
    @Log(title = "个人采集商品SKU", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerCollectProductSkuService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
